package com.iamk.semanticsegment;


public class ImageWindow {
	int d;
	int cX;
	int cY;
	double[][] imageWindow;
	
	
	public ImageWindow(int d,int cX,int cY) {
		this.d = d;
		this.cX = cX;
		this.cY = cY;
		imageWindow = new double[d][d];
	}
	
	public void getValueImageWindow(double[][] imgChannel){
		for(int i = 0; i < d; i++){
			for(int j = 0; j < d; j++){
				if(((cX+i-(d-1)/2 >= 0) && (cX+i-(d-1)/2 <= imgChannel.length - 1) && (cY+j-(d-1)/2 >= 0) && (cY+j-(d-1)/2 <= imgChannel[0].length - 1))){
					imageWindow[i][j] = imgChannel[cX+i-(d-1)/2][cY+j-(d-1)/2];
				}
			}
		}
	}
	
	public double getStandardDeviation(double[][] imgChannel){
		double Vij = 0;
		double muy = getMuy();
		for(int m = 0; m < d; m++){
			for(int n = 0; n < d; n++){
				Vij += Math.pow(imageWindow[m][n] - muy, 2);
			}
		}
		Vij = Math.sqrt((1/Math.pow(d, 2))*Vij);
		return Vij;
	}
	
	private double getMuy(){
		double muy = 0;
		for(int i = 0; i < d; i++){
			for(int j = 0; j < d; j++){
				muy+= imageWindow[i][j];
			}
		}
		muy = (1/Math.pow(d, 2))*muy;
		return muy;
	}
}
